﻿Public Class HangVe
	Inherits DataProvider

    Public Function save(ByVal dtohangve As DTO.HangVe) As Integer
        Dim sql = "INSERT INTO HangVe(Ten,GhiChu) VALUES('" + dtohangve.ten + "','" + dtohangve.ghichu + "')"
        Return Me.SaveData(sql)
    End Function

    Public Function lay_dataset() As DataSet
        Dim sqlstr As String = "SELECT * FROM HangVe"
        Return GetDT(sqlstr)
    End Function

    Public Function Insert(ByVal dto_hangve As DTO.HangVe)
        Dim sql_query As String = "INSERT INTO HangVe(Ten, GhiChu) VALUES('" + dto_hangve.ten + "', '" + dto_hangve.ghichu + "')"
        If IsNothing(Me.SaveData(sql_query)) Then
            Return Nothing
        End If
        Dim id As Integer = Integer.Parse(GetValue("SELECT max(id) from HangVe"))
        Return id
    End Function

    Public Function Update(ByVal dto_hangve As DTO.HangVe)
        Dim sql_query As String = "Update HangVe set Ten = '" + dto_hangve.ten + "', GhiChu = '" + dto_hangve.ghichu + "' where id = " + dto_hangve.id
        Return Me.SaveData(sql_query)
    End Function

    Public Function chek(ByVal tenhv As String) As DataSet
        Dim sql As String = "SELECT * FROM HangVe WHERE Ten='" + tenhv + "'"
        Return GetDT(sql)
    End Function

End Class
